import os
from time import sleep

from selenium.webdriver.common.by import By

from common.base import Base
from common.functions import open_browser


class GoodsPhoto(Base):
    # 点击商品管理标签
    def click_goods_management(self):
        self.base_click((By.XPATH, '//div[@id="menu-list"]/ul/li[2]'))

    # 点击添加新商品标签
    def click_add_new_goods(self):
        self.base_click((By.LINK_TEXT, '添加新商品'))

    # 点击商品相册
    def click_gallery(self):
        self.base_switch_default_iframe()
        self.base_switch_iframe((By.ID, 'main-frame'))
        self.base_click((By.ID, 'gallery-tab'))

    # 上传商品图片
    def upload_photo(self, content):
        aotoframe_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
        file = os.path.join(os.path.abspath(aotoframe_path), 'image', f'{content}')
        self.base_send_keys((By.CLASS_NAME, 'webuploader-element-invisible'), file)

    # 点击重置按钮
    def reset(self):
        self.base_switch_default_iframe()
        self.base_switch_iframe((By.ID, "main-frame"))
        self.base_click((By.XPATH, "//div[@class='button-div']/input[3]"))

    # 点击确定按钮
    def sure(self):
        self.base_switch_default_iframe()
        self.base_switch_iframe((By.ID, "main-frame"))
        self.base_click((By.XPATH, "//div[@class='button-div']/input[2]"))


